/*
  封装模块：统一处理token操作
  1、缓存中只能存储字符串
  2、我们需要的信息是对象
*/
const KEY = 'hm-toutiao-mobile-123'
// 存储token
export const setUser = (userInfo) => {
  // localStorage.setItem(KEY, '[object Object]')
  // localStorage.setItem(KEY, userInfo.toString())
  localStorage.setItem(KEY, JSON.stringify(userInfo))
  // localStorage.setItem(KEY, '{"token":"adsfasdfa","refresh_token":"dsafasfdasdfasdf"}')
}
// 删除token
export const delUser = () => {
  localStorage.removeItem(KEY)
}
// 获取token
export const getUser = () => {
  // const ret = localStorage.getItem(KEY)
  // ret = '{"token":"adsfasdfa","refresh_token":"dsafasfdasdfasdf"}'
  // ret.token
  return JSON.parse(localStorage.getItem(KEY))
}
